//
//  ViewController.m
//  本地通知
//
//  Created by student on 16/4/1.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)btnPressed:(id)sender
{
    UILocalNotification *n=[[UILocalNotification alloc]init];
    n.fireDate=[NSDate dateWithTimeIntervalSinceNow:10];
    //是否重复触发
    n.repeatInterval=kCFCalendarUnitMinute;
    
    n.alertBody=@"时间到了，洗洗睡吧";
    n.alertAction=@"时间到了，洗洗睡吧";
    
    //4.声音
    n.soundName=@"myMusic.caf";
    
    //角标
    n.applicationIconBadgeNumber = [UIApplication sharedApplication].scheduledLocalNotifications.count+1;
    
    //附带的信息
    n.userInfo=@{@"notiId":@"1"};
    
    //计划这个通知
    [[UIApplication sharedApplication] scheduleLocalNotification:n];
    
}

- (IBAction)cancleBtnPressed:(id)sender
{
    UIApplication *app=[UIApplication sharedApplication];
    NSArray *notis=app.scheduledLocalNotifications;
    for (UILocalNotification *n in notis) {
        NSDictionary *dict=n.userInfo;
        if([dict[@"notiId"] isEqualToString:@"1"])
        {
            [app cancelLocalNotification:n];
            
        }
    }
    
}
@end
